package com.huzz.util.spring;

import com.huzz.util.artword.ArtPdCharacter;
import com.huzz.util.artword.ArtWordUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.net.InetAddress;
import java.util.Arrays;

/**
 * @Name 项目启动后执行
 * @Description 描述
 * @Author 童年的纸飞机
 * @Since 2023-08-2023/8/3 11:11
 */
@Component
public class InitializeAfter {

    @Autowired
    private ApplicationContext applicationContext;

    @PostConstruct
    public void StartInitialize() throws Exception {
        Environment environment = applicationContext.getBean(Environment.class);
        String serverName = environment.getProperty("spring.application.name");
        String path = environment.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }
        for (int i = 0; i < 40; i++) {System.out.print(ArtPdCharacter.GREEN_BIG_SOLID_CIRCLE);}

        System.out.println();
        System.out.println("--启动成功--");
        ArtWordUtil.printArtWord(StringUtils.isNotEmpty(serverName) ? serverName : "OK", "#", 14);
        System.out.println("Swagger访问地址: http://" + InetAddress.getLocalHost().getHostAddress() + ":" + environment.getProperty("server.port") + path + "/doc.html");

        for (int i = 0; i < 40; i++) {System.out.print(ArtPdCharacter.GREEN_BIG_SOLID_CIRCLE);}
        System.out.println();
    }
}
